A Sneak Peek at StableValue and SegmentMapper
Per-Ake Minborg on October 24, 2024This video demystifies the work that is going on in two different efforts to make Java even better: StableValues and SegmentMapper.
Some internal JDK classes are relying heavily on the annotation jdk.internal.vm.annotation.@Stable
to mark scalar and array fields whose values or elements will change ‘at most once’, thereby providing crucial performance, energy efficiency, and flexibility benefits.
But the powerful @Stable
annotation cannot be used directly in Java applications thereby severely restricting its applicability. The StableValue
rectifies this imbalance between internal and client code by providing safe wrappers around the @Stable
annotation.
Hence, all the important benefits of @Stable
are now made available to regular Java developers and third-party library developers.
The Foreign Function & Memory API (the FFM API), introduced in Java 22, provides access to structured memory. Sadly, only access to primitive values like int
and long
were available.
SegmentMapper
fixes this shortcoming and allows structured memory to be mapped to standard Java composites like record
classes, thereby significantly improving the versatility of the FFM API.
Recorded at Devoxx Belgium 2024.